A computing device, such as a server, router, desktop computer, laptop, etc., and other devices having processor logic and memory, includes an operating system layer and an application layer to enable the device to perform various functions or roles. The operating system layer includes a “kernel”, i.e., master control program, that runs the computing device. The kernel provides task management, device management, and data management, among others. In other words, the kernel sets the standards for application programs that run on the computing device. The application layer includes programs, i.e., executable instructions, which are located above the operating system layer and accessible by a user. As used herein, “user” space, or “user-mode” implies a layer of code which is less privileged than the layer of code which is in the operating system layer or “kernel” space.
In an operating system, a process refers to a running program which has a state and may have an input and output. Each process has one or more threads. A thread is an executable set of instructions being executed on a processor. A thread is sometimes referred to as a lightweight process. For example, a process contains attributes shared by all executing threads in the in the process, such as an address space, file descriptors, variables of an executing instance of a program, etc. Processes and threads are well known in the art and are described, for example, in Modern Operating Systems, Andrew S. Tannenbaum, (1992).
Many applications, or processes may be running at the same time on a computing device. The kernel manages the set of processes such that each process is provided with processor cycles. The kernel provides a set of services, referred to as “system calls” to allow the processes to interact with the kernel. In a system call, the process calls a routine in the kernel (system) to undertake some specific task. For example, a system call referred to as “gettimeofday” is used in Unix systems to retrieve time.
Many application programs use time information, e.g., “time of day”, and use it often. Some example uses include time-stamps for file modifications and database transactions. Taking the difference between times is often used to measure intervals. A slow time of day interface can become a performance limiter. The use of time information has become so frequent that many processors provide software with a hardware clock of some sort that can be read quickly. Such clocks may not indicate the date and time directly, but rather count at some known rate. Hardware counters provides an affordable solution and can be associated with computing device components, e.g., processors, rather easily.
When a process involves a time measurement, a user process calls, e.g., queries, into the operating system with a request for time. The operating system is then expected to do something with hardware to return time. For example, in one operating system environment, the operating system may retrieve an offset and a scale factor which can be applied to a count from a counter and convert the count to date and time. In this example, the offset is additive and accounts for when the counter started. The scale factor is multiplicative and accounts for a difference in rates between the counter and external standard clock rates, i.e. as measured by an office wall clock. The counter can be converted to wall clock time using the formula: Wall_time=(scale_factor*hardware_counter)+offset. The operating system query can be expensive in terms of lines of program coding and processor time used since the query is often implemented as a system call. This query, however, does not pose a system performance issue because the scale factor and offset do not change. As such a program will only have to call a routine for these values once.
However, in multiprocessor computer devices, the hardware usually provides a separate and independent counter for each processor. These counters possess all of the properties of the counter described above, except that they may not be synchronized. As a result the scale factor and offset discussed above may not be the same for each processor. For example, the processors may not all run at the same speed, each processor's counter may start with a different initial value, and/or both. In a multiprocessor environment, the executing threads of a process may be switched on and off of a processor and/or from one processor to another (referred to herein as “context switches”) for efficient utilization of computing resources. When this occurs while the thread is gathering time information it is possible that the scale factor and offset being used by the thread will be inappropriate for the counter value used and/or the counter value will not be current.